package com.cx.rabbit;

import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Date;

@Component
public class Producer {
    // 定义了一套针对AMQP协议的基础操作
    @Autowired
    private AmqpTemplate rabbitTemplate;

    public boolean send(Integer id){
        String message = "hello3-> " + id  + " -> "+ new Date();
        System.out.println("Sender: " + message);
        // 产生一个字符串，并发送到名为hello的队列中
        this.rabbitTemplate.convertAndSend("helloWorld3", message);
        return true;
    }
}
